package org.jasig.cas.util;
import java.math.BigInteger;
import java.security.MessageDigest;

import org.jasig.cas.authentication.handler.PasswordEncoder;

/**
 * SHA加密
 * 
 * @author tanjun
 * @version 1.0
 * @since 1.0
 */
public class EncryptionUtil implements PasswordEncoder{

	public static final String KEY_SHA = "SHA";
	
	/**
	 * SHA加密
	 * 
	 * @param data
	 * @return
	 * @throws Exception
	 */
	private static byte[] encryptSHA(byte[] data) throws Exception {

		MessageDigest sha = MessageDigest.getInstance(KEY_SHA);
		sha.update(data);
		return sha.digest();
	}

	@Override
	public String encode(String password){
		
		BigInteger sha=null;
		try {
			sha = new BigInteger(EncryptionUtil.encryptSHA(password.getBytes()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sha.toString(32);
	}
}